package com.iversonx.responsibility_chain.example_1.v1;

import org.springframework.stereotype.Service;

/**
 *
 **/
@Service
public class FeeRequestService {
    public String request(FeeRequest parameter) {
        String result;
        double fee = parameter.getFee();
        if(fee < 500) {
            result = projectHandle(parameter);
        } else if(fee < 1000) {
            result = deptHandle(parameter);
        } else {
            result = ceoHandle(parameter);
        }
        return result;
    }
    
    /**
     * 项目经理审批
     * @param parameter
     * @return
     */
    private String projectHandle(FeeRequest parameter) {
        String result;
        if("Lee".equalsIgnoreCase(parameter.getUsername())) {
            result = "同意";
        } else {
            result = "拒绝";
        }
        return "项目经理" + result + parameter.getUsername() + "的费用申请";
    }
    
    /**
     * 部门经理审批
     * @param parameter
     * @return
     */
    private String deptHandle(FeeRequest parameter) {
        String result;
        if("Lee".equalsIgnoreCase(parameter.getUsername())) {
            result = "同意";
        } else {
            result = "拒绝";
        }
        return "部门经理" + result + parameter.getUsername() + "的费用申请";
    }
    
    /**
     * ceo审批
     * @param parameter
     * @return
     */
    private String ceoHandle(FeeRequest parameter) {
        String result;
        if("Lee".equalsIgnoreCase(parameter.getUsername())) {
            result = "同意";
        } else {
            result = "拒绝";
        }
        return "CEO" + result + parameter.getUsername() + "的费用申请";
    }
}
